#include <stdio.h>
#include <stdlib.h>

// Base class
typedef struct {
    double (*area)(void*);
} Shape;

// Derived class 1
typedef struct {
    Shape base;
    double radius;
} Circle;

double Circle_area(void* self) {
    Circle* c = (Circle*)self;
    return 3.14 * c->radius * c->radius;
}

// Derived class 2
typedef struct {
    Shape base;
    double length;
    double width;
} Rectangle;

double Rectangle_area(void* self) {
    Rectangle* r = (Rectangle*)self;
    return r->length * r->width;
}

int main() {
    Circle circle = {{Circle_area}, 5.0};
    Rectangle rectangle = {{Rectangle_area}, 4.0, 6.0};

    Shape* shapes[] = {(Shape*)&circle, (Shape*)&rectangle};

    for (int i = 0; i < 2; i++) {
        printf("Area: %lf\n", shapes[i]->area(shapes[i]));
    }

    return 0;
}